using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using AtletIS.DomainModel.Entities.Main;

namespace AtletIS.Database.Mapping.Main
{
    public class DisciplineListMap : EntityTypeConfiguration<DisciplineList>
    {
        public DisciplineListMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            this.Property(t => t.Name)
                .HasMaxLength(100);

            this.Property(t => t.Description)
                .HasMaxLength(100);

            this.Property(t => t.OfficialStartTime)
                .HasMaxLength(5);

            this.Property(t => t.StartTime)
                .HasMaxLength(8);

            this.Property(t => t.Note)
                .HasMaxLength(100);

            this.Property(t => t.ActivePerformanceHeader)
                .HasMaxLength(20);

            // Table & Column Mappings
            this.ToTable("DisciplineList");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.Name).HasColumnName("Name");
            this.Property(t => t.Description).HasColumnName("Description");
            this.Property(t => t.ExternalId).HasColumnName("ExternalId");
            this.Property(t => t.ParentId).HasColumnName("ParentId");
            this.Property(t => t.CompetitionId).HasColumnName("CompetitionId");
            this.Property(t => t.DisciplineId).HasColumnName("DisciplineId");
            this.Property(t => t.CategoryId).HasColumnName("CategoryId");
            this.Property(t => t.Day).HasColumnName("Day");
            this.Property(t => t.OfficialStartTime).HasColumnName("OfficialStartTime");
            this.Property(t => t.StartTime).HasColumnName("StartTime");
            this.Property(t => t.Status).HasColumnName("Status");
            this.Property(t => t.DisciplineCode).HasColumnName("DisciplineCode");
            this.Property(t => t.Note).HasColumnName("Note");
            this.Property(t => t.InnerCount).HasColumnName("InnerCount");
            this.Property(t => t.MeasurementId).HasColumnName("MeasurementId");
            this.Property(t => t.Relay).HasColumnName("Relay");
            this.Property(t => t.ActivePerformanceId).HasColumnName("ActivePerformanceId");
            this.Property(t => t.ActivePerformanceHeader).HasColumnName("ActivePerformanceHeader");
            this.Property(t => t.Active).HasColumnName("Active");
            this.Property(t => t.Sync).HasColumnName("Sync");
            this.Property(t => t.WebId).HasColumnName("WebId");
            this.Property(t => t.Modified).HasColumnName("Modified");

            // Relationships
            this.HasOptional(t => t.Category)
                .WithMany(t => t.DisciplineList)
                .HasForeignKey(d => d.CategoryId);
            this.HasOptional(t => t.Competition)
                .WithMany(t => t.DisciplineLists)
                .HasForeignKey(d => d.CompetitionId);
            this.HasOptional(t => t.Discipline)
                .WithMany(t => t.DisciplineLists)
                .HasForeignKey(d => d.DisciplineId);
            this.HasOptional(t => t.DisciplinesStatus)
                .WithMany(t => t.DisciplineLists)
                .HasForeignKey(d => d.Status);

        }
    }
}
